'''
CodeJam Practice 
Created on 2012-12-20

@author: festony
'''

from cj_lib import *
from properties import *

import math
import fractions


curr_file_name = 'D-large-practice'
#curr_file_name = 'D-small-practice'
#curr_file_name = 'test'

# map(int, input_lines.pop(0).split(' '))

#for a sequence with N elements, there are N! different permutations
#record T(i, N) as the number of permutations that have i and only i elements in right places (as sorted)
#e.g. for 4 elements sequence [1,2,3,4], there are 6 permutations with 2 and only 2 elements in right places:
#1 2 4 3
#1 3 2 4
#1 4 3 2
#2 1 3 4
#3 2 1 4
#4 2 3 1
#thus T(2, 4) = 6
#assume T(0, 0) = 1, easy to have:
#
#1) for 1 <= i <= N, T(i, N) = C(i, N) * T(0, N-i) (e.g for N = 6, i = 3: in case there are 3 elements just 
#in right places, we need to pick a combination of any 3 different elements ( C(3, 6) ), assume these 3 
#elements are in places and the other 3 elements are not in place, then for each combination, it's equivalent
#to 3 elements sequence that has no element in right place)
#
#2) for i = 0, T(0, N) = N! - (Sigma|i = 1~N (T(i, N))) (Excluding all cases with i > 0, the rest cases are
#of i == 0.)
#
#Then we can easily calculate T with any small enough i and N.
#
#for N element sequence (with no element in place), assume the expect number of hit-the-table is Xn (assume X0 = 0)
#
#from the initial status, after 1 hit, the sequence might be changed to:
#still N elements not in place (total case number: T(0, N)): need another Xn hits in average;
#1 elements in place (total case number: T(1, N)): N-1 elements not in places, need another Xn-1 hits in average;
#2 elements in places (total case number: T(1, N)): another Xn-2 hits;
#
#as there is already 1 hit happened, we have the average hit number is:
#(Sigma|i=0~N (T(i, N) * (Xn-i + 1))) / N! (the total number of all cases)
#== Xn!
#as we already have all T(i, N) and X0, we can then easily calculate all Xn when N is small enough
#
#
#Not finished! Observe X2 == 2, X3 == 3, X4 == 4 ...
#Could be Xn == N? worth try!
#and it works!





def input_dividing_func(input_lines):
    total_case = int(input_lines.pop(0))
    case_inputs = []
    for i in range(total_case):
        input_lines.pop(0)
        case_inputs.append(map(int, input_lines.pop(0).split(' ')))
    return case_inputs
    
def process_func(func_input):
    print func_input
    seq = func_input
    sseq = sorted(seq)
    N = 0
    for i in range(len(seq)):
        if seq[i] != sseq[i]:
            N += 1
    
    return float(N)

run_proc(process_func, input_dividing_func, curr_working_folder, curr_file_name)


